﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;
using Helper;

namespace SchoolAdministration
{
    public partial class FeeItem : System.Web.UI.Page
    {
        private int billid = 0;
        private readonly BLFee _blfee = new BLFee();
        protected void Page_Load(object sender, EventArgs e)
        {
            GridBill();
        }

        protected void BtnLoan_Click(object sender, EventArgs e)
        {
            BillItem item = new BillItem();
            item.billItemId = billid;
            item.billItem = TxtFeeItem.Text;
            int result = _blfee.SaveBillItem(item);
            if (result > 0)
            { 
                Helper.Alert.Show("FeeItem Entered successfully");
                GridBill();
                Clear();
            
            }
        }
        public void Clear()
        {
            TxtFeeItem.Text = string.Empty;
        }

        public void GridBill()
        {
            gvBillItem.DataSource = _blfee.GetBillItem();
            gvBillItem.DataBind();
        }

        protected void gvBillItem_RowEditing(object sender, GridViewEditEventArgs e)
        {

            gvBillItem.EditIndex = e.NewEditIndex;
            GridBill();

        }

        protected void gvBillItem_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvBillItem.EditIndex = -1;
            GridBill();

        }

        protected void gvBillItem_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            BillItem bitem = new BillItem();
            GridViewRow row = gvBillItem.Rows[e.RowIndex];
             bitem.billItem = ((TextBox)(row.Cells[2].Controls[0])).Text;
            bitem.billItemId = Convert.ToInt32(((TextBox)(row.Cells[1].Controls[0])).Text);
           
            gvBillItem.EditIndex = -1;
            GridBill();
        }

       
    }
}